package com.esisa.business.test;

import java.util.Date;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import com.esisa.business.AuthentificationManager;
import com.esisa.business.VeterinaireManager;
import com.esisa.models.Betail;
import com.esisa.models.Compte;
import com.esisa.models.CreteresVaccinantion;
import com.esisa.models.DosageMedicament;
import com.esisa.models.Fermier;
import com.esisa.models.Medicament;
import com.esisa.models.TypeBetail;
import com.esisa.models.VaccinationCatalogue;
import com.esisa.models.Veterinaire;
import com.esisa.utils.BusinessFactory;
import com.esisa.utils.HibernateSessionFactory;

public class Main {

	public Main() {
		System.out.println("********* Debut de Test *****************");
		testAddMedicamentToCatalogue();
		System.out.println("********* Fin de Test   *****************");
	}
	private void testAddMedicamentToCatalogue() {
		VeterinaireManager veterinaireManager=BusinessFactory.getVeterinaireManager();
		Session session = HibernateSessionFactory.getSessionFactory().openSession();
		Transaction tran = session.beginTransaction();
		Medicament medicament=(Medicament) session.get(Medicament.class,"ALLEGROCINE");
		VaccinationCatalogue catalogue=(VaccinationCatalogue) session.get(VaccinationCatalogue.class,(long) 2);
		for(DosageMedicament d:catalogue.getDosagesMedicament()){
			System.out.println(d.toString());
		}
		DosageMedicament dosageMedicament=new DosageMedicament();
		dosageMedicament.setQuantite(3);
		dosageMedicament.setRytheme(2);
		dosageMedicament.setUniteDosage("m");
		dosageMedicament.setUniteRytheme("day");
		dosageMedicament.setMedicament(medicament);
//		dosageMedicament.setVaccinationCatalogue(catalogue);
		
		catalogue.getDosagesMedicament().add(dosageMedicament);
		System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
		for(DosageMedicament d:catalogue.getDosagesMedicament()){
			System.out.println(d.toString());
		}
			session.update(catalogue);
		tran.commit();
//		dosageMedicament.setMedicament(medicament);
		
//		veterinaireManager.updateCatalogue(catalogue);
		
		
	}
	private void testNouveauCatalogue() {
		VeterinaireManager veterinaireManager=BusinessFactory.getVeterinaireManager();
		
		 Veterinaire v=veterinaireManager.find((long) 102);
		 VaccinationCatalogue vaccinationCatalogue=new VaccinationCatalogue("summer",new Date(), new Date());
		 CreteresVaccinantion creteresVaccinantion=new CreteresVaccinantion();
		 creteresVaccinantion.setAgeMaximal(23);
		 creteresVaccinantion.setPoidsMinimal(23);	 
		 vaccinationCatalogue.setCreteresVaccinantion(creteresVaccinantion);
		 
		 veterinaireManager.createCatalogue(vaccinationCatalogue);
		 v.getVaccinationCatalogues().add(vaccinationCatalogue);
		 
		 veterinaireManager.update(v);
		 
		 
		
	}
	private void testLoginFermier() {
		AuthentificationManager authentificationManager=BusinessFactory.getAuthentificationManager();
		authentificationManager.login("zeroual.abdellah", "zeroual.abdellah");
//		Session session = HibernateSessionFactory.getSessionFactory().openSession();
//		Transaction tran = session.beginTransaction();
//		
//		Compte compte=(Compte)session.get(Compte.class,"zeroual.abdellah");
//		System.out.println(compte.getPersonne().getDateNaissance());
//		tran.commit();
		
		
		
	}
	private void FermierManagerAlami() {
		com.esisa.business.FermierManager fermierManager =BusinessFactory.getFermierManager();
		TypeBetail typeBetail = new TypeBetail();
		typeBetail.setType("Bovine");
		typeBetail.setImage("/images/ssss.png");
		Betail betail = new Betail();
		betail.setDateNaissance(new Date());
		//betail.setRace("Alami");
		betail.setTypeBetail(typeBetail);
		fermierManager.createBetail(betail);
		}

	private void FermierManager() {
		com.esisa.business.FermierManager fermierManager=BusinessFactory.getFermierManager();
		Fermier fermier=new Fermier();
		fermier.setNom("Alami");
		fermier.setSalaire(2323);
		
		TypeBetail t=BusinessFactory.getAdminManager().findTypeBetail("bovine");
		
		fermier.setTypeBetail(t);
		
		Compte compte=new Compte("anti_maroc", "8372");
		compte.setGrade("fermier");
		fermier.setCompte(compte);
		compte.setPersonne(fermier);
		fermierManager.create(fermier);
		
	}
	private void AdminManager() {
			com.esisa.business.AdminManager adminManager=BusinessFactory.getAdminManager();
//			TypeBetail typeBetail=new TypeBetail();
//			typeBetail.setType("Ovine");
//			typeBetail.setImage("/images/bovine.png");
//			adminManager.createTypeBetail(typeBetail);
			System.out.println(adminManager.findAllTypeBetail());
	}
	private void veterinaireManager() {
		VeterinaireManager veterinaireManager = BusinessFactory.getVeterinaireManager();
		Veterinaire veterinaire=new Veterinaire();
		veterinaire.setNom("Zero");
		veterinaire.setPrenom("Med");
		Compte compte=new Compte("hmida", "83673");
		veterinaire.setCompte(compte);
		compte.setPersonne(veterinaire);	
		veterinaireManager.create(veterinaire);
	}
	public static void main(String[] args) {
		new Main();

	}

}
